package com.example.smartcity.ui.smartCity.Adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.smartcity.R
import com.example.smartcity.SmartCityApplication.Companion.context
import com.example.smartcity.logic.utils.Toast.Companion.showToast
import com.example.smartcity.ui.smartCity.activitytModule.SmActivity_2
import com.example.smartcity.ui.smartCity.activitytModule.SmViewPagerActivity
import com.example.smartcity.ui.smartCity.activitytModule.SspActivity
import com.example.smartcity.ui.smartCity.activitytModule.logIssueActivity
import com.example.smartcity.ui.smartCity.model.SmartCityEntity

/**
 *
 *  ANDROID STUDIO 2022
 *  @emil 2506789532@qq.com
 *  SmartCityRecyclerViewAdapter --- @ikun 2023/2/4 23:59
 **/
class SmartCityRecyclerViewAdapter(
    val listData: List<SmartCityEntity>
) : RecyclerView.Adapter<SmartCityRecyclerViewAdapter.HolderView>(){
    inner class HolderView(v: View) : RecyclerView.ViewHolder(v){
        // 获取控件
        val ReImage = v.findViewById<ImageView>(R.id.SmImageView)
        val ReTitle = v.findViewById<TextView>(R.id.SmTitle)
        val ReContend = v.findViewById<TextView>(R.id.SmContend)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HolderView {
        val root = LayoutInflater.from(parent.context).inflate(R.layout.smartcity_recyclerview_item, parent, false)
        val view = HolderView(root)

        view.itemView.setOnClickListener {
            if(view.ReTitle.text == "党建动态") parent.context.startActivity(Intent(parent.context, SmViewPagerActivity::class.java))
            if (view.ReTitle.text == "党员学习") parent.context.startActivity(Intent(parent.context, SmActivity_2::class.java))
            if (view.ReTitle.text == "建言献策") parent.context.startActivity(Intent(parent.context, logIssueActivity::class.java))
            if (view.ReTitle.text == "随手拍") parent.context.startActivity(Intent(parent.context, SspActivity::class.java))
        }

        return view
    }

    override fun getItemCount() = listData.size

    override fun onBindViewHolder(holder: HolderView, position: Int) {
        val data = listData[position]
        Glide.with(context)
            .load(data.SmImageView)
            .into(holder.ReImage)
        holder.ReTitle.text = data.SmTitle
        holder.ReContend.text = data.SmContend
    }
}